﻿namespace ScrumLite.Services.Contracts
{
    using System;
    using System.Collections.Generic;
    using System.Runtime.Serialization;
    using System.Globalization;

    [DataContract]
    public class Deliverable
    {        
        [DataMember]
        public Guid Id { get; set; }

        [DataMember]
        public int Moniker { get; set; }

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public bool IsDefective { get; set; }

        //TODO: REFACTOR THIS. ITS IN LINQCOMMITMENTS SERVICE
        private static int GetYearWeek(DateTime date)
        {
            CultureInfo invariant = CultureInfo.InvariantCulture;
            return invariant.Calendar.GetWeekOfYear(date,
                                   invariant.DateTimeFormat.CalendarWeekRule,
                                   invariant.DateTimeFormat.FirstDayOfWeek);
        }

        [DataMember]
        public string FullName
        {
            get
            {
                int week = Deliverable.GetYearWeek(ReleasedOn);
                return string.Format(CultureInfo.InvariantCulture, "w({0}) {1} ({2})", week.ToString(CultureInfo.InvariantCulture), Name, ReleasedOn.ToString("yyyy/MM/dd", CultureInfo.InvariantCulture));
            }
            // setter must exists because if not json serialization throws
            private set {}
        }
                 
        [DataMember]
        public DateTime ReleasedOn { get; set; }

        [DataMember]
        public Uri Url { get; set; }

        [DataMember]
        public WorkArea[] WorkAreas { get; set; }

       

    }
}